package exam.model.dao;

import java.util.HashMap;
import java.util.List;

import exam.model.entity.TSubQuestionEntity;
import exam.system.dao.AbstractDAO;

public class TSubQuestionDAO extends AbstractDAO<TSubQuestionEntity>{
	
	public TSubQuestionDAO() {
		super(TSubQuestionEntity.class);
	}
	
	public List<TSubQuestionEntity> selectListSubQuestion() {
		return super.selectList("from TSubQuestionEntity");
	}
	
	public TSubQuestionEntity selectByPk(long id) {
		return super.selectByPk(id);
	}
	
	public int insertSubQuestion(TSubQuestionEntity tSubQuestionEntity) {
		return super.insert(tSubQuestionEntity);
	}
	
	/**
	 * updateSubQuestion: cập nhật 20/05/2012
	 * @param tSubQuestionEntity
	 * @return int
	 */
	public int updateSubQuestion(TSubQuestionEntity tSubQuestionEntity) {
		String query = "update TSubQuestionEntity s set s.subject=:subject, s.updateDate=:updateDate " +
				" where s.subQuestId=:subQuestId";
		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("subject", tSubQuestionEntity.getSubject());
		params.put("updateDate", tSubQuestionEntity.getUpdateDate());
		params.put("subQuestId", tSubQuestionEntity.getSubQuestId());
		return jdbcManager.executeByQueryParams(query, params).getInt();
			
	}
	
	/**
	 * deleteSubQuestion
	 * @param subQuestId
	 * @return
	 */
	public void deleteSubQuestion(long subQuestId) {
		super.delete(subQuestId);
	}
}
